package pro.spring.controller.frontController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;



@Controller
@RequestMapping("yk")
public class YKLoginController extends BaseController{
	
	private Integer pagesize = 10 ;
	
	@RequestMapping(value="xli.html",method=RequestMethod.GET)
	public String xianxiali(@RequestParam(value = "p", defaultValue = "1")Integer pagenum,ModelMap map,String key,HttpServletRequest request,
			HttpServletResponse response){
		map.put("pages",udiscusserService.getByXianxia(5, pagesize, pagenum));
		return "/page/front/disc/xianxiali";
	}
	
	@RequestMapping(value="thli.html",method=RequestMethod.GET)
	public String themli(@RequestParam(value = "p", defaultValue = "1")Integer pagenum,String key,ModelMap map,HttpServletRequest request,
			HttpServletResponse response){
		map.put("pages",themeService.getPaginationInfo(key,pagenum,pagesize));
		return "/page/front/disc/theli";
	}
	
	@RequestMapping(value="tho/{id}.html",method=RequestMethod.GET)
	public String themo(@RequestParam(value = "p", defaultValue = "1")Integer pagenum,@PathVariable int id,ModelMap map,HttpServletRequest request,
			HttpServletResponse response){
		HttpSession session=request.getSession();
		Integer uId = (Integer)session.getAttribute("uId");
		if(uId!=null){
			Integer drId = themeService.selectByPrimaryKey(id).getUdiscusserDrId();
			return "redirect:../../them/themone.html?id="+drId;
		}else{
			map.put("theme",themeService.selectByPrimaryKey(id));
			map.put("pages",udiscussService.getThemeOne(id, pagenum, pagesize));
			return "/page/front/disc/themeo";
		}
	}
	
	
}
